import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ExpansionPanelDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => ExpansionPanelState();
}

class ExpansionPanelState extends State<ExpansionPanelDemo> {
  bool _isExpanded = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ExpansionPanel'),
        centerTitle: true,
      ),
      body: Container(
        padding: EdgeInsets.all(15),
        child: Column(
          children: <Widget>[
            //点击折叠按钮实现面板伸缩
            ExpansionPanelList(
              expansionCallback: (int panelIndex, bool isExpanded) {
                setState(() {
                  _isExpanded = !isExpanded;
                });
              },
              children: [
                ExpansionPanel(
                    headerBuilder: (BuildContext context, bool isExpanded) {
                      return Container(
                        padding: EdgeInsets.all(15),
                        child: Text('标题'),
                      );
                    },
                    body: Container(
                      padding: EdgeInsets.all(15),
                      width: double.infinity,
                      child: Text('内容'),
                    ),
                    //设置面板的状态，true展开，false折叠
                    isExpanded: _isExpanded)
              ],
            ),
          ],
        ),
      ),
    );
  }
}
